package com.example.smartf.repository.mysql;

import com.example.smartf.model.mysql.Traindata;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface TraindataRepository extends JpaRepository<Traindata,String> {



    //按照deviceID进行查找 所有天数的信息
    List<Traindata> findAllByTraindataKeyDeviceIDOrderByTraindataKey_Days(String deviceID);

    //按照deviceID，days查找 其中一条的数据
    Traindata findByTraindataKey_DaysAndTraindataKey_DeviceID(Integer days, String deviceID);

    //按照deviceID 删除训练数据
    @Transactional
    int deleteAllByTraindataKeyDeviceID(String deviceID);

    @Transactional
    @Modifying
    @Query("update Traindata set cgr = :cgr where traindataKey.deviceID = :deviceID and traindataKey.days = :days")
    int updateCgr(String deviceID, Integer days, Double cgr);

    @Transactional
    @Modifying
    @Query("update Traindata set light = :light where traindataKey.deviceID = :deviceID and traindataKey.days = :days")
    int updatelight(String deviceID, Integer days, Double light);

}
